package com.proxy.parser.result;



import com.proxy.common.constant.SqlType;
import com.proxy.common.model.ProxyTable;
import com.proxy.parser.ParsedResult;

import java.util.*;

/**
 * Created by liufish on 16/11/1.
 */
public class SelectResult implements ParsedResult {

    final List<?> selects = new ArrayList<>();

    final Object forms  = null;

    final Object where = null;

    Object orderBy = null;

    Object groupBy = null;

    boolean forUpdate = false;


    // limit


    //表集合
    final Map<String, ProxyTable> tables = new LinkedHashMap<String, ProxyTable>();

    //字段
    final Map<ProxyTable.Column, ProxyTable.Column> columns = new LinkedHashMap<ProxyTable.Column, ProxyTable.Column>();

    //条件
    final List<ProxyTable.Condition> conditions = new ArrayList<>();

    //关系
    final Set<ProxyTable.Relationship> relationships = new LinkedHashSet<ProxyTable.Relationship>();

    //排序
    final List<ProxyTable.Column> orderByColumns = new ArrayList<>();

    //分组
    final Set<ProxyTable.Column> groupByColumns = new LinkedHashSet<>();


    //limit
    ProxyTable.Limit limit;

    //如果是层级关系,当前不为空
    String currentTable;

    //参数
    List<Object> parameters =  new ArrayList<>();





    public Map<String, ProxyTable> getTables() {
        return tables;
    }

    public Map<ProxyTable.Column, ProxyTable.Column> getColumns() {
        return columns;
    }

    public List<ProxyTable.Condition> getConditions() {
        return conditions;
    }

    public Set<ProxyTable.Relationship> getRelationships() {
        return relationships;
    }

    public List<ProxyTable.Column> getOrderByColumns() {
        return orderByColumns;
    }

    public Set<ProxyTable.Column> getGroupByColumns() {
        return groupByColumns;
    }

    public String getCurrentTable() {
        return currentTable;
    }

    public void setCurrentTable(String currentTable) {
        this.currentTable = currentTable;
    }

    public List<Object> getParameters() {
        return parameters;
    }


    @Override
    public SqlType getSqlType(){
        return SqlType.SELECT;
    }


    public boolean isForUpdate() {
        return forUpdate;
    }

    public void setForUpdate(boolean forUpdate) {
        this.forUpdate = forUpdate;
    }

    public ProxyTable.Limit getLimit() {
        return limit;
    }

    public void setLimit(ProxyTable.Limit limit) {
        this.limit = limit;
    }
}
